package com.itheima.dubbo.web;

import com.itheima.dubbo.service.User;
import com.itheima.dubbo.service.UserFace;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class UserController {
    @DubboReference//远程服务的调用
    //@DubboReference(timeout = 1900)//消费者接口超时时间
    // @DubboService(methods = {
    //        @Method(name = "getById",timeout = 2000)
    //})//消费者方法超时时间
    //@DubboService(version = "1.0.0")//指定版本
    //@DubboReference(loadbalance = "roundrobin")//负载均衡策略修改 轮询
    //@DubboReference(cluster = "failfast")//容错机制 只调用一次
    UserFace userFace;

    @GetMapping("hello")
    public String hello(String username) {
        return userFace.hell(username);
    }

    @GetMapping("getById")
    public User getById(Long id) {
        //隐式参数
        RpcContext.getContext().setAttachment("name","胡浩楠");
        return userFace.getById(id);
    }
}
